package command;

import object.*;

import java.io.File;
import java.util.Iterator;
import java.util.Map;

public class CommitCommand {
    private String msg;

    public CommitCommand(String message) {
        msg = message;
    }

    public void excute() throws Exception {
        Stage stage = Stage.deserialize();
        Map<String, String[]> addFiles = stage.getAddedFiles();
        Iterator iterator = addFiles.entrySet().iterator();

        while (iterator.hasNext()) {
            Map.Entry entry = (Map.Entry) iterator.next();
            String key = (String) entry.getKey();
            String[] val = (String[]) entry.getValue();
            File file = new File(key);
            if (file.isFile()) {
                Blob blob = new Blob(file);
            }
            else {
                Tree tree = new Tree(file);
            }

        }
        Tree tree = new Tree(new File("." ));

        Commit commit = new Commit(tree, msg);

        HEAD head = HEAD.deserialize();

        head.updateHEAD(commit);

        head.writeObject();

        stage.clearStage();
        stage.writeObject();
    }
}
